const express = require('express')
const router = express.Router()
const db = require('../db')
const consts = require('../../consts/Consts')
const uploadMobileRouter = require('./Upload')
router.use('/upload', uploadMobileRouter)

/**
 * @api {get} http://127.0.0.1:3658/taskmobile/getAllTasks 手机端获取任务
 * @apiDescription 手机端获取所有本人任务
 * @apiName getAllTasks
 * @apiGroup 手机任务
 * @apiParam (query) {String} phoneNumber 手机号
 *
 * @apiSuccess {Number} code 状态码.
 * @apiSuccess {Json} result  json数据.
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "code" : 20000,
 *      "result" : {}
 *
 *  }
 * @apiVersion 1.0.0
 */
router.get('/getAllTasks', (req, res, err) => {
  const phoneNumber = req.query.phoneNumber
  console.log('taskmobile-getAllTasks: %s', phoneNumber)
  db.TaskMobileDb.getAllTasks(phoneNumber, (err, list) => {
    if (err) throw err
    console.log('user:%o', list)
    res.send({
      code: consts.RES_OK,
      result: list
    })
  })
})

module.exports = router
